package edu.umassd.visual;

import java.awt.BorderLayout;
import java.awt.Toolkit;

import javax.annotation.PostConstruct;
import javax.swing.JFrame;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class UI extends JFrame
{
	private static final long serialVersionUID = -4024104611983102036L;

	@Autowired
	private RADDACLDisplay display;

	@Autowired
	private OptionPanel options;

	@PostConstruct
	protected void init()
	{
		setUndecorated(true);
		setLayout(new BorderLayout());
		setSize(Toolkit.getDefaultToolkit().getScreenSize());

		display.setSize(calcWidth(), calcHeight());

		add(options, BorderLayout.EAST);
		add(display, BorderLayout.CENTER);
		// important to call this whenever embedding a PApplet.
		// It ensures that the animation thread is started and
		// that other internal variables are properly set.
		display.init();

		// pack();
		setVisible(true);
	}

	private int calcHeight()
	{
		return (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
	}

	private int calcWidth()
	{
		int opsWidth = options.getPreferredSize().width;
		int screenWidth = (int) Toolkit.getDefaultToolkit().getScreenSize()
				.getWidth();

		return screenWidth - opsWidth;
	}

	public static void main(String[] args)
	{
		new ClassPathXmlApplicationContext("/display-beans.xml");
	}
}
